package cn.gok.code.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;

/**
 * @ClassName HandlerTool
 * @Description TODO
 * @Author HP
 * @Date 16:20 2022/7/21
 * @Version 1.0
 *
 * 自动填充策略
 * 疑问：为什么这里命名和数据库字段名不一样可以呢？updateTime、createTime？
 **/
@Slf4j
@Component
public class HandlerTool implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ");
        this.setFieldValByName("createTime",new Date(),metaObject);
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ");
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }
}
